<?php

session_start();

class Core {

	private static $_instance;

	public static function getInstance() {
		if (self::$_instance == null) {
			self::$_instance = new Core;
		}

		return self::$_instance;
	}

	public function init() {
		//$this->checkSession();

		$class = $this->getControllerClass();
		$method = $this->getControllerMethod();

		$c = new ReflectionClass($class);
		$n = $c->newInstance();

		$m = $c->getMethod($method);

		$m->invoke($n, $method);
	}

	private function getControllerClass() {
		$class = $_GET['c'];

		$class = ucfirst($class);

		$class .= 'Controller';

		return $class;
	}

	private function getControllerMethod() {
		$method = $_GET['m'];

		return $method;
	}

	private function checkSession() {
		if (empty($_SESSION)) {
			if ($this->getControllerMethod() !== 'login' || $this->getControllerMethod() !== 'loginProcess') {
				header('Location: index.php?c=employee&m=login');
			}
		}
	}
}